package com.systemsetup.systemsetup.web.mapper;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.systemsetup.systemsetup.model.Role;
import com.systemsetup.systemsetup.model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    IPage<User> userListPage(IPage page, @Param("param") JSONObject jsonParam);

    IPage<User> userListForBUPage(IPage page, @Param("param") JSONObject jsonParam);

    @Select(" SELECT" +
            " r.*  " +
            " FROM " +
            " userrole u " +
            " LEFT JOIN role r ON u.role_id = r.id " +
            " WHERE" +
            " u.user_id = #{id} " +
            " AND r.type = #{type}"

    )
     List<Role> selectUserPermissionList(Role role);

    @Select(" SELECT" +
            " r.*  " +
            " FROM " +
            " userrole u " +
            " LEFT JOIN role r ON u.role_id = r.id " +
            " WHERE" +
            " AND r.type = #{type}"

    )
    List<Role> selectPermissionList(Role role);

    int getSameUserNameListSize(JSONObject jsonParam);

    /**
     * 根据homeId获取user信息
     * @param jsonParam
     * @return
     */
    List<User> getUserList(String jsonParam);

    List<User> userListByOrgId(JSONObject jsonParam);

    List<User> getUserListByOrgId(JSONObject jsonParam);
    List<User> getUserListB(JSONObject jsonParam);

    void updateCid(User user1);

    /**
     * 设备导出的时候调用
     * @param str
     * @return
     */
    User userInfo(Map<String, Object> map);

    /**
     * 获取所有和设备号相关的cid
     * @param jsonParam
     * @return
     */
    List<String> getAllCidFromNumber(JSONObject jsonParam);

    /**
     * 获取所有和设备号相关的openId
     * @param jsonParam
     * @return
     */
    List<String> getAllOpenIdFromNumber(JSONObject jsonParam);
}
